'''
Created on Aug 19, 2009

@author: echeek
'''

def nextTerm(n):
    r=0;
    a=n;
    while a>0:
        r*=10;
        r+=(a%10);
        a=int(a/10);
    return r+n;

def isPalindrome(n):
    st=str(n);
    for x in range(len(st)/2):
        if( st[x] != st[-(x+1)]):
            return False;
    return True;

def Euler55():
    count=0;
    for n in range(0,10000):
        trials=0;
        term=n;
        while True:
            term=nextTerm(term);
            if(isPalindrome(term)):
                break;
            trials+=1;
            if(trials==50):
                count+=1;
                break;
            
    print count;
 
''' 
term=349;
for x in range(10):
    print term;
    term=nextTerm(term);
    if(isPalindrome(term)):
        print term;
        break;
'''
    
Euler55();

